package 数组.移除元素27;

import utils.Utils;

public class Solution {
    public static int removeElement(int[] nums, int val) {
        int count = 0;
        for(int i=0,j=0;j<nums.length;j++){
            if(nums[j] != val){
                int tmp = nums[i];
                nums[i] = nums[j];
                nums[j] = tmp;
                count++;
                i++;
            }
        }

        Utils.printIntArr(nums);
        return count;
    }

    public static void main(String[] args) {
       int[] nums = {0,1,2,2,3,0,4,2};
       int val = 2;
       Utils.printInt(removeElement(nums,val));
    }
}
